#include "mainwindow.h"

#include <QApplication>
#include <iostream>
#include <QSqlQuery>

using std::cout;
using std::endl;

int sql_Connect()
{
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("library.db");
    if(!db.open())
    {
        cout<<"SQL databade open error"<<endl;
        //return -1;
    }
    else
    {
        cout<<"SQL database connect successfully" <<endl;
        //return 0;
    }
    QSqlQuery query;
    query.exec(QObject::tr("create table student (id int primary key, name vchar)"));
    query.exec(QObject::tr("insert into student values (0,'刘明')"));
    query.exec(QObject::tr("insert into student values (1,'陈刚')"));
    query.exec(QObject::tr("insert into student values (2,'王红')"));
    return 0;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    sql_Connect();
    MainWindow w;
    w.show();
    return a.exec();
}
